package com.bw.mallshop.mvvm.view;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;
import com.bw.mallshop.R;
import com.bw.mallshop.widget.ShowNavigator;
import com.google.android.material.bottomnavigation.BottomNavigationView;

//软件框架页，主要作用为切换二级菜单下的fragment
public class FrameActivity extends AppCompatActivity {

    private BottomNavigationView frame_nav_bottom;
    private NavHostFragment frame_nav_group;
    private NavController controller;
    private ShowNavigator showNavigator;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        init();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    }

    private void init(){
        frame_nav_bottom = findViewById(R.id.frame_nav_bottom);
        frame_nav_group = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.frame_nav_group);
        controller = frame_nav_group.getNavController();
        showNavigator = new ShowNavigator(this,getSupportFragmentManager(),frame_nav_group.getId());
        controller.setGraph(R.navigation.navigation);
        controller.getNavigatorProvider().addNavigator(showNavigator);
        NavigationUI.setupWithNavController(frame_nav_bottom,controller);
    }

}
